#!/usr/bin/env bash
#ulimit -u 65535
#ulimit -n 4096
function Timezone(){
    #[[ `cat /etc/issue |grep 'CentOS'` ]] && SysName='CentOS';
    #egrep -i "centos" /etc/issue && SysName='centos';
	whereis -b yum | grep '/yum' >/dev/null && SysName='CentOS';
	rm -rf /etc/localtime;
	ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime;

	echo '[ntp Installing] ******************************** >>';
	[ "$SysName" == 'CentOS' ] && yum install -y ntp || apt-get install -y ntpdate;
	ntpdate -u pool.ntp.org;
	StartDate=$(date);
	StartDateSecond=$(date +%s);
	echo "Start time: ${StartDate}";
}

function CloseSelinux(){
    /usr/sbin/setenforce 0
	[ -s /etc/selinux/config ] && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config;
	setenforce 0 >/dev/null 2>&1;
}

function nginx_repo(){
    wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    rpm -ivh  nginx-release-centos-6-0.el6.ngx.noarch.rpm
}

function mariadb10_repo(){
    cat  /etc/yum.repos.d/mariadb10.repo  << EOF
# MariaDB 10.0 CentOS repository list - created 2013-08-23 13:08 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
}

function nginx_install(){
    yum update
    yum -y install nginx
}

function mariadb10_install(){
    yum update
    yum -y install MariaDB-client MariaDB-server MariaDB-devel
}

function php_install(){
    yum update
    yum --enablerepo=remi install php php-fpm php-mysql  php-curl  php-mbstring  php-gd
    chkconfig php-fpm on
    service php-fpm start
}

function ubuntu_lnmp(){
    sudo apt-get install selinux-utils
    sudo setenforce 0
    sudo apt-get install software-properties-common
    sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
    sudo add-apt-repository 'deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main'
    sudo apt-get update
    sudo apt-get install nginx
    sudo apt-get install mariadb-server
    sudo apt-get install php5-fpm  php5-mysql   php5-cgi  php5-dev   php5-gd  php5-curl  php5-cli
}
